/*
 * condition.h
 *
 *  Created on: 2008-12-15
 *      Author: fanliangliang
 */

#ifndef POSIX_CONDITION_H_
#define POSIX_CONDITION_H_

#include "bits/lock.h"
#include <vector>
#include <climits>
#include <sys/time.h>

BEGIN_NAMESPACE_TOXIC

class Condition {
	CLASS_UNCOPYABLE(Condition)
public:
	Condition();
	~Condition();

	void wait(ScopedLock& lock);
	bool wait(ScopedLock& lock, unsigned long millisecond);

	void notify();
	void notifyAll();

private:
	void makeTimeout(struct timespec* pts, unsigned long millisecond);

private:
	pthread_cond_t _condition;
};

END_NAMESPACE_TOXIC

#endif /* POSIX_CONDITION_H_ */
